/* Copyright 2016 Adobe Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. AIG. Copyright © American International Group,Inc. All rights reserved. emailto:contact AT dmp-support@aig.com This HTML file supports the AEM touch UI dialog License as published by the AIG; either 2 Peach Tree Hill Rd, Livingston, NJ 07039.*/ /* * * This is js file is used to * add the generic javascripts for the components * hero banner * blade image moble view. * Also js to make teaser component clickable. * The code is specific to redesign2020 code base. * */ /* update the dynamic header to the function */ /*IE11 POLYFILL for "endswith" */ if (!String.prototype.endsWith) { String.prototype.endsWith = function (searchString, position) { /* get search string */ const subjectString = this.toString(); if ( typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length ) { position = subjectString.length; } position -= searchString.length; /* get last Index of subject string */ const lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } function updatedynamicheader() { const dh_container = $('.dynamic_header > .cmp-container'); /*this checks if there is a dynamic header class */ if (dh_container.length > 0) { var dh_height = 0; dh_container.each(function () { const dh_id = $(this).attr('id'); dh_height = dh_id.split('-')[1]; $(this).children('.aem-Grid').css('height', dh_height); }); } } /* we need to move the active link in the international mobile navigation - start*/ function moveactive() { $( '.mobile__only.mobile__drawer .audience > .cmp-navigation > .cmp-navigation__group > .cmp-navigation__item--active' ) .remove() .appendTo( $( '.mobile__only.mobile__drawer .audience > .cmp-navigation > .cmp-navigation__group' ) ); } /* we need to move the active link in the international mobile navigation - end*/ $(document).ready(function () { updatedynamicheader(); updateHeroForm(); updateCustomForm(); /* code to open external links in a new window starts */ $( '.accordion,.button,.carousel,.container,.list,.navigation,.text,.title,.teaser,.teaserflex,.tabs,.image' ).each(function () { if ($(this).hasClass('external-link')) { $(this) .find('a') .each(function () { const hostName = new RegExp('/' + window.location.host + '/'); const $this = $(this); const alink = $this.prop('href'); const aLinkAttr = $this.attr('href'); const damlink = '/content/dam'; const testdamlink = this.href.indexOf(damlink) > -1; if ( (!hostName.test(alink) && aLinkAttr && !alink.match(/^[mailto|tel|javascript:void]/)) || testdamlink ) { $this.addClass('external-link'); $this.attr('title', $(this).text()); $this.append('external_link'); $this.attr('target', '_blank').attr('rel', 'noopener noreferrer'); } }); /* code to remove external link icon to image starts*/ $( ".image a span[class^='custom-icons']:contains('external_link')" ).remove(); $( ".teaser .cmp-teaser__title a span[class^='custom-icons']:contains('external_link')" ).remove(); /* code to remove external link icon to image end */ } }); /* code to open external links in a new window end */ /* Code to add rel="noopener noreferrer" to all external links with target _blank attr - Start */ $( 'a[href][target]:not([href^="tel:"],[href^="#"],[href^="mailto:"],[href^="javascript:"])' ).prop('rel', 'noopener noreferrer'); /* Code to add rel="noopener noreferrer" to all external links with target _blank attr - End */ if ($('#dmp-forms-VALIC').length > 0) { const url = $('#dmp-forms-VALIC input[name = ":redirect"]') .val() .split('.html'); $('#dmp-forms-VALIC').attr('action', url[0]); } if ($('#dmp-forms-sponsorfit').length > 0) { const url1 = $('#dmp-forms-sponsorfit input[name = ":redirect"]') .val() .split('.html'); $('#dmp-forms-sponsorfit').attr('action', url1[0]); } /* Code block to append blade image component - start */ $('.blade-with-image').each(function () { const baldeteaser = $(this) .children('.cmp-container') .find('.aem-Grid') .html(); $(this).append(baldeteaser); }); //we need to make sure we are on the new nav /* sticky naviagtion mobile view */ if ($('.sticky_nav').length) { if ($('.header__bar').length) { $(mobilStickyNav).insertAfter('.header__bar'); } else { $(mobilStickyNav).insertAfter('.hamburg'); } const $baseEdit = $('.sticky_nav .button:first a .cmp-button__text').text(); if ($('#edit-base').length) { $('#edit-base').html($baseEdit); } const mobstickylinks = $('.sticky_nav .cmp-container').html(); $('.mob-sticky-nav').append(mobstickylinks); $('.mobilestickynav .mob-sticky-nav .button .cmp-button').removeAttr('id'); $('.mob-sticky-nav').children().removeAttr('id'); } $('.navigation-wrapper').click(function () { $('.mob-sticky-nav').show(); $('.modal-header').show(); $('.header-stickynavpan').hide(); }); $('.close-icon').click(function (e) { e.preventDefault(); $('.header-stickynavpan').show(); $('.mob-sticky-nav').hide(); $('.modal-header').hide(); }); /* sticky navigtion mobile view - end*/ /* Teaser title link check and update title link starts */ if ($('.cmp-teaser').length > 0) { $('.cmp-teaser').each(function () { if ( !$(this).find('.cmp-teaser__title a').length && $(this).find('.cmp-teaser__action-container a').length ) { const linkVal = $(this) .find('.cmp-teaser__action-container a') .attr('href'); $(this) .find('.cmp-teaser__title') .wrapInner( '' ); } }); } /* Teaser title link check and update title link ends */ /* Social media component mail show hide js starts */ $('.sharing .sharethis .email a').click(function () { $('.sharing .sharethis .email-modal').show(); }); $('.sharing .sharethis .email-modal-body button.close').click(function () { $('.sharing .sharethis .email-modal').hide(); }); /* Social media component mail show hide js end */ }); /*update the height of the header on resize. should add a debounce here */ $(window).on('resize', function () { updatedynamicheader(); updateHeroForm(); updateCustomForm(); }); $(window).on('resize', function () { updateHeroForm(); }); /* Sticky Navigation script - Start */ $(window).scroll(function () { const stickyNavigation = $('.sticky_nav'); if ( stickyNavigation.length && ($('.pre-footer').length || $('footer').length) ) { const footerName = $('.pre-footer').length ? '.pre-footer' : 'footer'; const stickyNav = stickyNavigation.offset().top; const stickyNavHeight = stickyNavigation.height(); onScrollUpdatePosition( $(this).scrollTop(), footerName, '.sticky_nav .cmp-container', stickyNav, stickyNavHeight ); } }); /* Perform click action for sticky_nav: desktop - Start*/ $('.sticky_nav .cmp-container .button').click(function () { const linkId = $(this).find('.cmp-button').attr('href'); if(linkId.indexOf('flyout-dialog') === -1){ onScrollUpdatePosition( $(linkId).offset().top, '.sticky_nav', '.sticky_nav .cmp-container' ); stickyNavTraverse(linkId, false); } }); /* Perform click action for sticky_nav: desktop - End*/ /* Perform click action for sticky_nav: mobile - Start*/ $(document).on('click', '.modal-dialog .mob-sticky-nav .button', function () { const linkId = $(this).find('.cmp-button').attr('href'); onScrollUpdatePosition( $(linkId).offset().top, '.mob-sticky-nav', '.mob-sticky-nav .cmp-container' ); stickyNavTraverse(linkId, true); }); /* Perform click action for sticky_nav: mobile - End*/ /* Method to set fixed position for sticky_nav & sticky_nav aig_button : on scroll action - Start*/ function onScrollUpdatePosition( scrollTopPos, stickyElementClass, navElementClass, sideNavTopPosition, sideNavHeight ) { let stickyDivTopPosition = 0; if ($(stickyElementClass).length) { stickyDivTopPosition = $(stickyElementClass).offset().top; } if ( (scrollTopPos > stickyDivTopPosition && stickyElementClass === '.sticky_nav_jp') || (scrollTopPos > sideNavTopPosition && scrollTopPos + sideNavHeight < stickyDivTopPosition) ) { $(navElementClass).addClass('affix'); } else { $(navElementClass).removeClass('affix'); } if ($(window).width() > 641 && stickyElementClass !== '.sticky_nav_jp') { if ( (scrollTopPos > stickyDivTopPosition && stickyElementClass === '.sticky_nav') || (scrollTopPos > sideNavTopPosition && scrollTopPos + sideNavHeight < stickyDivTopPosition) ) { $(navElementClass).addClass('affix'); } else { $(navElementClass).removeClass('affix'); } } if ($(window).width() < 640) { if (scrollTopPos > stickyDivTopPosition) { $('.sticky_nav .cmp-container .aig_button').addClass('stick_bottom'); } else { $('.sticky_nav .cmp-container .aig_button').removeClass('stick_bottom'); } } } /* Method to set fixed position for sticky_nav & sticky_nav aig_button : on scroll action - End*/ /* Method to set window scroll position for sticky_nav & sticky_nav aig_button on click action - Start*/ function stickyNavTraverse(linkId, isMobile) { const stickyNavHeight = isMobile ? 10 : $('.container.sticky_nav .cmp-container').height(); let posi; if (isMobile) { posi = $('.sticky_nav .cmp-container .aig_button.stick_bottom').length ? $(linkId).parent('.container').offset().top - stickyNavHeight : $(linkId).parent('.container').offset().top; } else { posi = $('.sticky_nav .cmp-container.affix').length ? $(linkId).parent('.container').offset().top - stickyNavHeight : $(linkId).parent('.container').offset().top; } $('html, body').animate( { scrollTop: posi }, 50 ); } /* Method to set window scroll position for sticky_nav & sticky_nav aig_button on click action - End*/ /* sticky navigation end*/ function createCookie(location) { //set cookie to the current active link. const l = location; const d = new Date(); d.setTime(d.getTime() + 90 * 24 * 60 * 60 * 1000); const expiry = d.toUTCString(); //creating cookie with the index so that we can add that back to the correct location. //document.cookie = 'activeLink=' + l + ';expires=' + expiry + ';path=/'; } //the following code gets and then will set the cookie to display proper menu //remove the cookie creation below. used only for dev // //document.cookie = "landingcookiepath=individual"; //check host const hn = window.location.hostname; const landingcookiepath = getCookie('landingcookiepath'); if ( $('#aig-interim').length > 0 && hn.endsWith('.com') && landingcookiepath.length > 0 ) { /* Condition to check for landingcookiepath value and assign menu class name */ $('.audience') .children('nav') .children('ul') .children() .each(function (index, item) { if ( $(item) .children('.cmp-navigation__item-link') .attr('href') .includes(landingcookiepath) ) { $(item).addClass('cmp-navigation__item--active'); } else { $(item).removeClass('cmp-navigation__item--active'); } }); } /* Start of setting up the latest active link to show for those pages where links are not active in menu */ function setActiveNav(){ // lets construct get active. then we convert to an array from get active so we can use the some loop const getActive = $('.utility__bar .cmp-navigation__item--level-0:visible, .main__nav .cmp-navigation__item--level-0:visible'); const getMobileActive = $('.mobile__drawer .cmp-navigation__item--level-0'); //if no active link is found, we will update the first link to be active let noactive = false; /* Desktop Navigation starts */ if (getActive.length > 0) { //loop through array to find the active link. getActive.each(function (index, item) { $(item).on('click',function(){ createCookie(index); }); if ($(item).hasClass('cmp-navigation__item--active')) { noactive = true; createCookie(index); //lets break out of the loop since we are done with it. return item; } }); //this is used so that if the user lands on a utility link first if (!noactive) { //is there a cookie? if ( document.cookie.split(';').some(function (item) { return !item.trim().indexOf('activeLink='); }) ) { const activeLink = document.cookie.replace(/(?:(?:^|.*;\s*)activeLink\s*\=\s*([^;]*).*$)|^.*$/, '$1'); if(activeLink < getActive.length){ getActive[activeLink].classList.add('cmp-navigation__item--active'); }else{ //Reset cookie and first item will be active link getActive[0].classList.add('cmp-navigation__item--active'); createCookie(0); } } else { //no need to write a cookie here. If they continue on, it will be written later. getActive[0].classList.add('cmp-navigation__item--active'); createCookie(0); } } } else { /* Mobile Mode starts */ if (getMobileActive.length > 0) { //loop through array to find the active link. getMobileActive.each(function (index, item) { $(item).on('click',function(){ createCookie(index); }); if ($(item).hasClass('cmp-navigation__item--active')) { noactive = true; createCookie(index); //lets break out of the loop since we are done with it. return item; } }); //this is used so that if the user lands on a utility link first if (!noactive) { //is there a cookie? if ( document.cookie.split(';').some(function (item) { return !item.trim().indexOf('activeLink='); }) ) { const activeLink = document.cookie.replace(/(?:(?:^|.*;\s*)activeLink\s*\=\s*([^;]*).*$)|^.*$/, '$1'); if(activeLink < getMobileActive.length){ getMobileActive[activeLink].classList.add('cmp-navigation__item--active'); }else{ //Reset cookie and first item will be active link getMobileActive[0].classList.add('cmp-navigation__item--active'); createCookie(0); } } else { //no need to write a cookie here. If they continue on, it will be written later. getMobileActive[0].classList.add('cmp-navigation__item--active'); createCookie(0); } } } } } setActiveNav(); /** Code to move International Header mobile active element to the end so that the inactive items appear properly **/ moveactive(); /** Code to update annuities login component in desktop and mobile conditionally - start **/ function updateHeroForm() { $('.hero-banner-full-container').each(function () { const cmpContainer = $('.hero-banner-full-container .cmp-container'); /** Code to update annuities login component in mobile conditionally - start **/ if ($(window).width() < 768) { const heroForm = cmpContainer.find('.hero-banner-form').html(); if ( $(this).find('.wrap-form form').length === 0 && cmpContainer.find('.hero-banner-form').length > 0 ) { $(this).append('
' + heroForm + '
'); $(this) .children('.cmp-container') .find('.hero-banner-form > form') .remove(); $('form[name*="lnr_annuities_login"]').attr('action', ''); } } /** Code to update annuities login component in mobile conditionally - end **/ /** Code to update annuities login component in desktop & tablet conditionally - start **/ if ($(window).width() >= 768 && $(this).children('.cmp-container')) { const heroForm = $(this).children('.cmp-container').find('.hero-banner-form > form') .length === 0 ? $(this).find('.wrap-form').html() : cmpContainer.find('.hero-banner-form').html(); if ( $(this).children('.cmp-container').find('.hero-banner-form > form') .length === 0 && $(this).find('.wrap-form > form').length > 0 ) { $(this) .children('.cmp-container') .find('.hero-banner-form') .html(heroForm); $(this).children('.cmp-container').siblings('.wrap-form').remove(); $('form[name*="lnr_annuities_login"]').attr('action', ''); } } /** Code to update annuities login component in desktop & tablet conditionally - end **/ }); } /** Code to update annuities login component in desktop/mobile conditionally - end **/ /** Code to create Custom Select Dropdown - start **/ function selectCustomDropdown() { if ($('.custom-select').length) { /* To implement Hide dropdown outside click */ hideSelectDDOutsideClick(); /* To implement Custom dropdown using Un-ordered list */ $('.custom-select .cmp-form-options--drop-down').each(function (e) { if ($(this).closest('form').parent('.contact_form').length) { return; } const selectElement = $('select', this); const listItem = $('option', selectElement); let selectPicker = '